package com.lcq.study.re;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName PatternTest
 * @Description
 * @Author lichuanqi
 * @Date 2022/8/30 10:12
 * @Version 1.0
 **/
public class PatternTest {
    public static void main(String[] args) {
        test1();
        //groupMatch();
    }

    private static void groupMatch() {
        /**
         * 组匹配，([a-z]+)(\d+)两组匹配([a-z]+)和(\d+)
         * 因此m.groupCount() = 2
         * m.group(1)返回匹配([a-z]+)子串
         * m.group(2)返回匹配(\d+)子串
         */
        Pattern p=Pattern.compile("([a-z]+)(\\d+)([a-z]+)");
        Matcher m=p.matcher("aaa2223bb");
        System.out.println(m.matches());
        System.out.println(m.groupCount());
        System.out.println(m.end(1));
        System.out.println(m.group(1));
        System.out.println(m.group(2));
    }

    private static void test1() {
        String arg = "--class=aaa";
        /**
         * [^=]匹配除了=号外的所有字符
         */
        Pattern pattern = Pattern.compile("(--[^=]+)=(.+)");
        Matcher matcher = pattern.matcher(arg);
        if (matcher.matches()){
            System.out.println(matcher.group(1));
            System.out.println(matcher.group(2));
        }
    }
}
